package com.zp.crm.service.MarDevelopService.Impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.zp.crm.dao.MarDevelopDao.MarDevelopDao;
import com.zp.crm.dto.MarDevelopDao.MarDevelopDto;
import com.zp.crm.entity.MarDevelop.MarDevelopEntity;
import com.zp.crm.service.MarDevelopService.MarDevelopService;
import com.zp.crm.util.targetLog.Log;
@Service("mardevelopService")
public class MarDevelopServiceImpl implements MarDevelopService {

	@Resource
	public MarDevelopDao mDao;
	@Log(name="查询销售机会开发信息 ")
	@Override
	public Map<String, Object> select(String code) {
		Map<String, Object> map= new HashMap<>();
		if(code != null){
			
			List<MarDevelopEntity> list=mDao.selectByCode(code);
			
			String a=new MarDevelopDto().MarText(list);
			
			map.put("success", true);
			
			map.put("message", a);
			
		}else{
			map.put("success", false);
			map.put("message", null);
		}

		return map;
	}
	@Log(name="添加销售机会开发信息 ")
	@Override
	public Map<String, Object> insert(String code,String obj){
		List<MarDevelopEntity> list= new ArrayList<>();
		String[] a=obj.split(",");
		for(int i=0;i<a.length;i++){
			String b=a[i];
			String[] c=b.split("\\^");
			String q=c[0];String w=c[1];
			MarDevelopEntity entity = new MarDevelopEntity(code,w,q);
			list.add(entity);
		}
		int r=mDao.insert(list);
		Map<String, Object> map=new HashMap<>();
		if(r>0){
			map.put("success", true);
			map.put("message", "添加成功！");
		}else{
			map.put("success", false);
			map.put("message", "添加失败！");
		}
		
		return map;
	}
	
}
